package com.kedacom.freedomLabel.view.widget;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import android.os.Build;
import android.util.AttributeSet;
import android.view.Gravity;

import com.kedacom.freedomLabel.R;
import com.kedacom.lego.fast.widget.refreshlayout.util.DensityUtil;

public class SideTipView extends android.support.v7.widget.AppCompatTextView {

    private Paint tipPaint;
    private Path tipPath;
    private int radius;

    public SideTipView(Context context) {
        super(context);
        init();
    }

    public SideTipView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public SideTipView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
        setGravity(Gravity.CENTER);
    }

    private void init() {
        radius = DensityUtil.dp2px(25);
        tipPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        tipPaint.setColor(getResources().getColor(R.color.colorAccent));
        tipPaint.setStyle(Paint.Style.FILL);
        tipPath = new Path();
    }

    private int height;

    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        super.onSizeChanged(w, h, oldw, oldh);
        height = h;
    }

    @Override
    protected void onDraw(Canvas canvas) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            tipPath.addArc(0, height / 2 - radius, radius * 2, height / 2 + radius, 45, 270);
            tipPath.lineTo(radius * 2 + DensityUtil.dp2px(15), height / 2);
            canvas.drawPath(tipPath, tipPaint);
        }
        tipPath.close();
        super.onDraw(canvas);
    }
}